package com.anjubao.parking.municipal.user.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.user.constants.BalanceTypeEnum;
import com.anjubao.parking.municipal.user.dto.UserBalanceRecordDto;
import com.anjubao.parking.municipal.user.dto.UserInfoMgmtDto;
import com.anjubao.parking.municipal.user.form.UserQueryForm;
import com.anjubao.parking.municipal.user.service.ParkingUserMgmtService;
import com.anjubao.parking.municipal.user.service.UserBalanceRecordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhuchunfeng
 * @date 2019/7/22 16:54
 */
@RestController
@RequestMapping("/parking-mgmt-user")
@Slf4j
@Api(value = "user-service", tags = {"会员管理后台"})
public class ParkingUserMgmtController {

    @Resource
    private ParkingUserMgmtService parkingUserMgmtService;
    @Resource
    private UserBalanceRecordService userBalanceRecordService;

    @GetMapping("/user/list")
    @ApiOperation("会员列表")
    public ApiResult<List<UserInfoMgmtDto>> listUser(UserQueryForm form) {
        form.validate();
        IPage<UserInfoMgmtDto> userInfoMgmtDtoIPage = parkingUserMgmtService.listUser(form);
        return ApiResult.success(userInfoMgmtDtoIPage.getRecords(), (int) userInfoMgmtDtoIPage.getTotal());
    }

    /*
     * 查询指定月的充值消费记录
     */
    @GetMapping("/balances/records")
    @ApiOperation("用户充值消费账单查询接口")
    public ApiResult<List<UserBalanceRecordDto>> getUserBalanceRecords(@ApiParam(value = "16位用户编号", required = true) @RequestParam(value = "userCode", required = true) String userCode,
                                                                       @ApiParam(value = "当前页码，默认1") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                                       @ApiParam(value = "分页大小，默认9999") @RequestParam(value = "pageSize", defaultValue = "9999") Integer pageSize) {

        IPage<UserBalanceRecordDto> userBalanceRecords = userBalanceRecordService.getUserBalanceRecords(userCode, BalanceTypeEnum.RECHARGE.getCode(), page, pageSize);
        return ApiResult.success(userBalanceRecords.getRecords(),(int)userBalanceRecords.getTotal());
    }


}
